package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.CustomerFilter;
import com.aidex.biz.service.CustomerFilterService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 筛选客户条件Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/biz/bizCustomerFilter")
public class CustomerFilterController extends BaseController
{
    @Autowired
    private CustomerFilterService customerFilterService;

    /**
     * 查询筛选客户条件列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:list')")
    @GetMapping("/list")
    public R<PageInfo> list(CustomerFilter customerFilter, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                customerFilter.setCompanyId(null);
        }else{
                     customerFilter.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        customerFilter.setPage(new PageDomain(request, response));
        return R.data(customerFilterService.findPage(customerFilter));
    }

    /**
     * 获取筛选客户条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:query')")
    @GetMapping(value = "/{id}")
    public R<CustomerFilter> detail(@PathVariable("id") String id)
    {
        return R.data(customerFilterService.get(id));
    }

    /**
     * 新增筛选客户条件
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:add')")
    @Log(title = "筛选客户条件", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  CustomerFilter customerFilter)
    {
        return R.status(customerFilterService.save(customerFilter));
    }

    /**
     * 修改筛选客户条件
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:edit')")
    @Log(title = "筛选客户条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated CustomerFilter customerFilter)
    {
        return R.status(customerFilterService.save(customerFilter));
    }


    /**
     * 删除筛选客户条件
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:remove')")
    @Log(title = "筛选客户条件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(customerFilterService.deleteCustomerFilterByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(customerFilterService.findMaxSort(new CustomerFilter()));
    }

    /**
     * 导出筛选客户条件列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizCustomerFilter:export')")
    @Log(title = "筛选客户条件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(CustomerFilter customerFilter)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    customerFilter.setCompanyId(null);
            }else{
                         customerFilter.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<CustomerFilter> list = customerFilterService.findList(customerFilter);
        ExcelUtil<CustomerFilter> util = new ExcelUtil<CustomerFilter>(CustomerFilter.class);
        return util.exportExcel(list, "筛选客户条件数据");
    }

}
